//
//  BaseTabBarController.swift
//  FlameB
//
//  Created by 连俊 on 2020/7/30.
//  Copyright © 2020 连俊. All rights reserved.
//

import UIKit
import ESTabBarController_swift

class BaseTabBarController: ESTabBarController, UITabBarControllerDelegate {
    var tabBarImageView: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        edgesForExtendedLayout = .all
        automaticallyAdjustsScrollViewInsets = false
        self.delegate = self
        
        var tabbarH: CGFloat = 49.0

        if isIPhoneX {
            tabbarH = 83.0
        }
        
        self.tabBar.frame = CGRect(x: 0, y: UIScreen.appHeight()-49, width: UIScreen.appWidth(), height: tabbarH)
        self.tabBar.shadowImage = UIImage()
        self.tabBar.backgroundImage = UIImage()
        tabBarImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: UIScreen.appWidth(), height: tabbarH))
        tabBarImageView.backgroundColor = UIColor.white
        tabBarImageView.contentMode = .scaleToFill
        self.tabBar.addSubview(tabBarImageView)
        
        tabBar.layer.shadowOffset = CGSize(width: 0, height:  -4)
        tabBar.layer.shadowColor = UIColor.init(rgb: 0x666666).withAlphaComponent(0.1).cgColor
        tabBar.layer.shadowOpacity = 0.8
        tabBar.layer.shadowRadius = 3
        
        let home = HomeViewController()
        home.tabBarItem = ESTabBarItem.init(creatAnimationItemView(), title: "首页", image: UIImage(named: "tab_icon_home_0"), selectedImage: UIImage(named: "tab_icon_home_1"), tag: 0)
        
        let inputPage = InputServerPage()
        inputPage.tabBarItem = ESTabBarItem.init(creatAnimationItemView(), title: "录入", image: UIImage(named: "tab_icon_mine_nor"), selectedImage: UIImage(named: "tab_icon_mine_selected"), tag: 1)
        
        let mine = MineViewController()
        mine.tabBarItem = ESTabBarItem.init(creatAnimationItemView(), title: "我的", image: UIImage(named: "tabs_icon_mine_normal"), selectedImage: UIImage(named: "tabs_icon_mine_sel"), tag: 2)
        
        self.viewControllers = [home,inputPage, mine]
        self.selectedIndex = 0
    }
    
    private func creatAnimationItemView() -> ESTabBarItemContentView {
        let itemView = ESTabBarItemContentView()
        itemView.textColor = UIColor.init(rgb: 0x666666)
        itemView.highlightTextColor = UIColor.init(rgb: 0x666666)
        return itemView
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
